import java.sql.*;

public class Main {
    public static void main(String[] args) {
        MySqlSessionFactory mySqlSessionFactory = new MySqlSessionFactory();
        UserMapper userMapper = mySqlSessionFactory.getMapper(UserMapper.class);
        User user = userMapper.SelectUserById(1);
//        User user = jdbcSelectById(1);
        System.out.println(user);
    }

    private static User jdbcSelectById(int id){
        String jdbcUrl = "jdbc:mysql://localhost:3306/test";
        String dbUser = "root";
        String password = "yyqyyds66";

        String sql = "select * from test.user where id = ?";
        try (Connection connection = DriverManager.getConnection(jdbcUrl,dbUser,password);
             PreparedStatement statement = connection.prepareStatement(sql)){
            statement.setInt(1,id);
            ResultSet rs = statement.executeQuery();
            if(rs.next()){
                User user = new User();
                user.setId(rs.getInt("id"));
                user.setAge(rs.getInt("age"));
                user.setName(rs.getNString("name"));
                return user;
            }

        }catch (SQLException e){
            e.printStackTrace();
        }
        return null;
    }
}
